<ot-view>

    <div class="row">
        <div class="col-md-12">
            <div class="alert alert-info" ng-show="loadingBranches">
                <span class="ot-loading-indicator"></span>
                Loading the project...
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-md-12 ot-view-title">
            {{project.name}}
            <ot-entity-embedded-decorations decorations="project.decorations"></ot-entity-embedded-decorations>
            <div ng-if="project.description" class="ot-description">
                {{project.description}}
            </div>
            <div ng-if="project.labels.length > 0" class="ot-project-label-container">
                <ot-project-label label="label" ng-repeat="label in project.labels" action="projectLabelFilter(label)"></ot-project-label>
                <span ng-if="project.links._labels" class="fa fa-pencil" title="Edition of labels" ng-click="editProjectLabels()"></span>
            </div>
        </div>
    </div>

    <ot-entity-disabled entity="project" callback="reloadProject()">
        The project is disabled.
    </ot-entity-disabled>

    <!-- Favorite branches -->
    <div class="row" ng-if="project.favouriteBranches.length > 0">
        <div class="col-md-12">
            <ot-section-title><span class="fa fa-star"></span> Favorite branches</ot-section-title>
            <table class="ot-project-branches">
                <tbody>
                <tr ng-repeat="branch in project.favouriteBranches | orderBy:getBranchTime:true"
                    ng-show="showDisabled || !(branch.disabled || branch.type == 'TEMPLATE_DEFINITION')">
                    <td class="ot-project-branch-name ot-decoration-list"
                        ng-class="{'ot-entity-disabled': branch.disabled}">
                        <span
                                class="fa fa-star ot-command"
                                title="Unsets as favourite"
                                ng-if="branch.links._unfavourite"
                                ng-click="branchUnfavourite(branch)"
                        ></span>
                        <a href="#/branch/{{branch.id}}">
                            {{branch.name}}
                        </a>
                        <ot-entity-embedded-decorations decorations="branch.decorations"></ot-entity-embedded-decorations>
                        <span
                                ng-show="showDisabled && branch.links._enable"
                                title="Enable the {{branch.name}} branch"
                                ng-click="enableBranch(branch)"
                                class="ot-command ot-command-enable"></span>
                        <span
                                ng-show="showDisabled && branch.links._disable"
                                title="Disable the {{branch.name}} branch"
                                ng-click="disableBranch(branch)"
                                class="ot-command ot-command-disable"></span>
                        <span
                                ng-show="showDisabled && branch.links._delete"
                                title="Delete the {{branch.name}} branch"
                                ng-click="deleteBranch(branch)"
                                class="ot-command ot-command-delete"></span>
                    </td>
                    <td>
                        <div class="ot-project-branch-promotion"
                             ng-if="branch.latestBuild.length > 0">
                            <span class="ot-description">Latest</span>
                            <span class="fa fa-arrow-right"></span>
                            <a href="#/build/{{branch.latestBuild[0].id}}"
                               title="Latest build on this branch">
                                {{branch.latestBuild[0].name}}
                            </a>
                        </div>
                        <div class="ot-project-branch-promotion"
                             ng-if="branch.latestBuild.length == 0">
                                    <span class="ot-description">
                                        <span class="fa fa-ban" title="No build on this branch"></span>
                                        No build
                                    </span>
                        </div>
                        <div class="ot-project-branch-promotion"
                             ng-repeat="promotionLevel in branch.promotionLevels">
                                    <span ng-if="promotionLevel.promotionRuns.length > 0">
                                        <a href="#/promotionLevel/{{promotionLevel.id}}">
                                            <ot-entity-image
                                                    entity="promotionLevel"></ot-entity-image>
                                            {{promotionLevel.name}}
                                        </a>
                                        <span class="ot-project-branch-promotion-build">
                                            <span class="fa fa-arrow-right"></span>
                                            <a href="#/build/{{promotionLevel.promotionRuns[0].build.id}}">{{promotionLevel.promotionRuns[0].build.name}}</a>
                                        </span>
                                    </span>
                            <span ng-if="promotionLevel.promotionRuns.length == 0">
                                        <a href="#/promotionLevel/{{promotionLevel.id}}">
                                            <ot-entity-image
                                                    entity="promotionLevel"></ot-entity-image>
                                            {{promotionLevel.name}}
                                        </a>
                                        <span class="fa fa-arrow-right"></span>
                                        <span class="fa fa-ban"></span>
                                    </span>
                        </div>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>

    <!-- All branches -->
    <div class="row">
        <div class="col-md-12">
            <ot-section-title><span class="fa fa-code-fork"></span> Branches</ot-section-title>
            <div class="ot-noentry" ng-if="project.branches.length == 0">
                No branch has been created yet.
            </div>
            <div class="row" ng-if="project.branches.length > 0">
                <div class="col-md-12">
                    <div class="ot-project-branch-filter input-group col-md-4"
                         ng-show="project.branches.length > 5">
                        <input class="form-control"
                               ng-model="branchFilter.name"
                               placeholder="Filter on branch names"/>
                        <span class="input-group-addon"><span class="fa fa-search"></span></span>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-3"
                     ng-repeat="branch in project.branches | filter:{name: branchFilter.name} | orderBy:getBranchTime:true"
                     ng-show="showDisabled || !(branch.disabled || branch.type == 'TEMPLATE_DEFINITION')">
                    <div class="ot-project-branch" ng-class="{'ot-entity-disabled': branch.disabled}">
                        <span
                                class="fa fa-star-o ot-command"
                                title="Sets as favourite"
                                ng-if="branch.links._favourite"
                                ng-click="branchFavourite(branch)"
                        ></span>
                        <span
                                class="fa fa-star ot-action"
                                style="color: yellow;"
                                title="Unsets as favourite"
                                ng-if="branch.links._unfavourite"
                                ng-click="branchUnfavourite(branch)"
                        ></span>
                        <a href="{{branch.links._page}}">
                            {{branch.name}}
                        </a>
                        <ot-entity-embedded-decorations decorations="branch.decorations"></ot-entity-embedded-decorations>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-5">
            <ot-section-title>Properties</ot-section-title>
            <div class="row">
                <div class="col-md-12">
                    <ot-entity-properties entity="{_properties: project.links._properties}"></ot-entity-properties>
                </div>
            </div>
            <ot-section-title>Extra information</ot-section-title>
            <div class="row">
                <div class="row">
                    <div class="col-md-12">
                        <ot-entity-extra entity="{_extra: project.links._extra}"></ot-entity-extra>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-7">
            <ot-entity-events entity="{_events: project.links._events}"></ot-entity-events>
        </div>
    </div>

</ot-view>